import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//引入elementPlus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

//全局引入axios
import axios from 'axios'

const app = createApp(App);

//配置全局路径
axios.defaults.baseURL = "http://localhost:80 80/his"
//将axios挂载到app对象上
app.config.globalProperties.$axios = axios
app.config.globalProperties.$baseUrl = "http://localhost:8080/his"
//跨域请求中传递cookie
axios.defaults.withCredentials = true

// 请求拦截器
axios.interceptors.request.use(
    config => {
      console.log('****************统一请求设置********************');
      // 设置统一的请求头，例如：token
      config.headers['token'] = window.localStorage.getItem("token");
      return config;
    },
    error => {
      // 请求错误的处理
      return Promise.reject(error);
    }
  );

//添加响应拦截器
axios.interceptors.response.use(function (response){
    //对响应数据做的事情
    console.log('响应拦截器',response);
    if(response.data.code == 50001){
        router.push('/login');
    }
    return response;
    },function (error){
        //对响应错误做的事情
        return Promise.reject(error);
    });

//使用elementPlus
app.use(ElementPlus).use(store).use(router).mount('#app')
